<?php 

namespace app\admin\controller;
use app\admin\server\Cate as CateServer;
use app\admin\model\Cate as CateModel;


class Cate extends Base 
{

 	/**
 	 * 分类列表
 	 * @return [type] [description]
 	 */
	public function lists()
	{
		if(request()->isAjax()){
			$result = (new CateServer())->getCatesByWhere();
			$return['total'] = count($result);  // 总数据
            $return['rows'] = $result;
            return json($return);
		}else{
			$pid = isset($_GET['pid']) ? $_GET['pid'] : 0;
			$this->assign('pid',$pid);
			return $this->fetch();
		}
		
	}


	/**
	 * 添加分类
	 */
	public function add()
	{
		if(request()->isAjax()){
			return (new CateServer())->save();
		}
		$cates = (new CateServer())->getCateTree();
		$this->assign('cates',$cates);
		// $this->assign('status',Config('cate'));
		return $this->fetch();
	}

	/**
	 * 修改分类
	 */
	public function update()
	{

		if(request()->isAjax()){
			return (new CateServer())->save();
		}

		$id = input('param.id');
		$info = (new CateModel())->get($id);
		$cates = (new CateServer())->getCateTree();
		$this->assign([
			'cates'=>$cates,
			'info' => $info
		]);
		// $this->assign('status',Config('cate'));
		return $this->fetch();
	}


	/**
	 * 删除分类
	 * @return [type] [description]
	 */
	public function del()
	{
		if(request()->isAjax()){
			return (new CateServer())->delete();
		}
	}



	 /**
     * 是否推荐首页
     * @return [type] [description]
     */
    public function is_show()
    {
        //修改状态
        $flag = (new CateServer())->saveStatusByID();
        return json(msg($flag['code'], $flag['data'], $flag['msg']));
    }
}